package cn.audit.service.role;

import cn.audit.bean.dto.BatchProcessing;
import cn.audit.bean.pojo.RoleManager;
import cn.audit.repository.role.RoleRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

/**
 * @Author: 李忆枫
 * @Date: 2019/5/19 17:12
 */
@Service
public class RoleService {

    @Resource
    private RoleRepository roleRepository;

    public List<RoleManager> findAll() {
        return roleRepository.findAll();
    }

    /**
     * 保存修改角色
     *
     * @param role
     */
    @Transactional(rollbackFor = Exception.class)
    public void save(RoleManager role) {
        roleRepository.save(role);
    }

    /**
     * 批量删除
     *
     * @param ids
     */
    @Transactional(rollbackFor = Exception.class)
    public void deleteById(List<Long> ids) {
        roleRepository.BatchRemove(ids);
    }

    /**
     * 根据id查找
     * @param id
     * @return
     */
    public RoleManager findById(Long id) {
        Optional<RoleManager> op = roleRepository.findById(id);
        return op.get();
    }


}
